* struct tm -> std::tm, memset of tm goes to {}.
* init std::tm related variables.
tidy found found the following warnigns related to our usage of
std::tm:
cppcoreguidelines-pro-type-member-init
and std::tm*:
cppcoreguidelines-init-variables
* make GPS_D600_Get var tm automatic storage duration
and intialize it.
static int process_data(const unsigned char* data)
{
static int remaining = 100;
- static struct tm tm;
+ static std::tm tm;
static time_t start, creation;
static route_head* track;
static unsigned char interval;
int xvasprintf(char** strp, const char* fmt, va_list ap);
char* strupper(char* src);
char* strlower(char* src);
-time_t mklocaltime(struct tm* t);
-time_t mkgmtime(struct tm* t);
+time_t mklocaltime(std::tm* time);
+time_t mkgmtime(std::tm* time);
bool gpsbabel_testmode();
gpsbabel::DateTime current_time();
QDateTime dotnet_time_to_qdatetime(long long dotnet);
static void
print_date_and_time(const time_t time, const int time_only)
{
- struct tm tm;
+ std::tm tm{};
char tbuf[32];
if (time < 0) {
char buff[128], tbuff[32];
char* c;
int len, n = 0;
- struct tm tm;
FWRITE("MsRc", 4); // Signature
FWRITE_i16(0x66); // Primary File Format
*/
- memset(&tm, 0, sizeof(tm));
-
+ std::tm tm{};
n = sscanf(gdb_release_date+7, "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
if (n != 6) {
// The $Date string in gdb_release_date[] above is bad.
n = strftime(tbuff, sizeof(tbuff), "%b %d %Y*%H:%M:%S", &tm);
if (n == 0) {
- // The build of the struct tm was bad.
+ // The build of the std::tm was bad.
fatal(MYNAME ": internal date generation error for %s\n", gdb_release_date + 7);
}
}
/*
- * GPS year: 2000+; struct tm year: 1900+
- * GPS month: 1-12, struct tm month: 0-11
+ * GPS year: 2000+; std::tm year: 1900+
+ * GPS month: 1-12, std::tm month: 0-11
*/
QDate gpsDate = QDate(header.dateStart.Year+2000, header.dateStart.Month, header.dateStart.Day);
time_t GPS_D600_Get(GPS_PPacket& packet)
{
UC* p;
- static struct tm ts;
+ std::tm ts{};
p = packet.data;
void GPS_D600_Send(GPS_PPacket& packet, time_t Time)
{
UC data[10];
- UC* p;
- struct tm* ts;
- p = data;
+ UC* p = data;
- ts = localtime(&Time);
+ std::tm* ts = localtime(&Time);
*p++ = ts->tm_mon+1;
*p++ = ts->tm_mday;
static void
encode_datetime(time_t datetime, unsigned char* buffer)
{
- struct tm* tm;
-
- if ((tm = gmtime(&datetime)) != nullptr) {
+ if (std::tm* tm = gmtime(&datetime); tm != nullptr) {
buffer[0] = tm->tm_year - 100;
buffer[1] = tm->tm_mon + 1;
buffer[2] = tm->tm_mday;
* SSSSSSMM MMMMHHHH Hdddddmm mmmmmmmm
*/
- struct tm tm;
-
- memset(&tm, 0, sizeof(tm));
+ std::tm tm{};
tm.tm_sec = buffer[0] & 0x3F;
tm.tm_min = ((buffer[0] & 0xC0) >> 6) | ((buffer[1] & 0x0F) << 2);
static void
decode_sbn_datetime(const unsigned char* buffer, Waypoint* waypt)
{
- struct tm tm;
+ std::tm tm{};
int ms = be_readu16(buffer + 6);
tm.tm_sec = ms / 1000;
// Uggh. strftime format exposed to user.
time_t time = dt.toTime_t();
- struct tm tm = *gmtime(&time);
+ std::tm tm = *gmtime(&time);
char buff[128];
strftime(buff, sizeof(buff), opt_title, &tm);
track->rte_name = buff;
dt = wpt->GetCreationTime();
}
time_t t = dt.toTime_t();
- struct tm tm = *gmtime(&t);
+ std::tm tm = *gmtime(&t);
char buff[128];
strftime(buff, sizeof(buff), opt_title, &tm);
track->rte_name = buff;
#include <cmath> // for fabs, lround
#include <cstdio> // for NULL, sscanf
-#include <cstring> // for memset, strchr, strncpy
+#include <cstring> // for strchr, strncpy
#include <ctime> // for gmtime
#include <QByteArray> // for QByteArray
{
int p1, p2, p3;
char sep[2];
- struct tm tm;
+ std::tm tm{};
int lconsumed = 0;
- memset(&tm, 0, sizeof(tm));
int ct = sscanf(str, "%d%1[-.//]%d%1[-.//]%d%n", &p1, sep, &p2, sep, &p3, &lconsumed);
if (consumed && lconsumed) {
*consumed = lconsumed;
if (opt_utc) {
res += xstrtoi(opt_utc, nullptr, 10) * SECONDS_PER_HOUR;
} else {
- struct tm tm = *gmtime(&res);
+ std::tm tm = *gmtime(&res);
res = mklocaltime(&tm);
}
return QDateTime::fromSecsSinceEpoch(res, Qt::UTC);
char is_localtime = 0;
garmin_fs_t* gmsd;
double d;
- struct tm ymd;
+ std::tm ymd{};
int src_datum = unicsv_datum_idx;
int ns = 1;
int ew = 1;
auto* wpt = new Waypoint;
wpt->latitude = kUnicsvUnknown;
wpt->longitude = kUnicsvUnknown;
- memset(&ymd, 0, sizeof(ymd));
int column = -1;
const QStringList values = csv_linesplit(ibuf, unicsv_fieldsep, "\"", 0, CsvQuoteMethod::rfc4180);
time_t t = date + time;
if (is_localtime) {
- struct tm tm;
- tm = *gmtime(&t);
+ std::tm tm = *gmtime(&t);
if (opt_utc) {
wpt->SetCreationTime(mkgmtime(&tm));
} else {
*/
time_t
-mkgmtime(struct tm* t)
+mkgmtime(std::tm* time)
{
static const int m_to_d[12] =
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
- short month = t->tm_mon;
- short year = t->tm_year + month / 12 + 1900;
+ short month = time->tm_mon;
+ short year = time->tm_year + month / 12 + 1900;
month %= 12;
if (month < 0) {
year -= 1;
result += (year - 1968) / 4;
result -= (year - 1900) / 100;
result += (year - 1600) / 400;
- result += t->tm_mday;
+ result += time->tm_mday;
result -= 1;
result *= 24;
- result += t->tm_hour;
+ result += time->tm_hour;
result *= 60;
- result += t->tm_min;
+ result += time->tm_min;
result *= 60;
- result += t->tm_sec;
+ result += time->tm_sec;
return (result);
}
* which is evaluated by mktime
*/
time_t
-mklocaltime(struct tm* t)
+mklocaltime(std::tm* time)
{
time_t result;
- struct tm check = *t;
+ std::tm check = *time;
check.tm_isdst = 0;
result = mktime(&check);
check = *localtime(&result);
if (check.tm_isdst == 1) { /* DST is in effect */
- check = *t;
+ check = *time;
check.tm_isdst = 1;
result = mktime(&check);
}
static time_t decode_date(uint32_t tim)
{
auto [sec, min, hour, mday, mon, year] = split_date(tim);
- struct tm t;
+ std::tm t{};
t.tm_sec = sec;
t.tm_min = min;
#include <cmath> // for fabs, pow
#include <cstdio> // for snprintf, sscanf
#include <cstdlib> // for strtod
-#include <cstring> // for strlen, strncmp, strcmp, memset
+#include <cstring> // for strlen, strncmp, strcmp
#include <ctime> // for gmtime, localtime, time_t, mktime, strftime
#include <optional> // for optional
time_t
XcsvFormat::sscanftime(const char* s, const char* format, bool gmt)
{
- struct tm stm;
- memset(&stm, 0, sizeof(stm));
+ std::tm stm{};
if (strptime(s, format, &stm)) {
if ((stm.tm_mday == 0) && (stm.tm_mon == 0) && (stm.tm_year == 0)) {
QString
XcsvFormat::writetime(const char* format, time_t t, bool gmt)
{
- static struct tm* stmp;
+ static const std::tm* stmp;
if (gmt) {
stmp = gmtime(&t);
QString
XcsvFormat::writehms(const char* format, time_t t, bool gmt)
{
- static struct tm no_time = tm();
- static struct tm* stmp = &no_time;
+ static const std::tm no_time{};
+ static const std::tm* stmp = &no_time;
if (gmt) {
stmp = gmtime(&t);